//
//  YFRequestManager.h
//  techand-iOS
//
//  Created by Yutian Duan on 16/7/16.
//  Copyright © 2016年 techand. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"

NS_ASSUME_NONNULL_BEGIN

typedef void (^YFRequestFailedBlock)(id returnValue);

typedef void (^YFRequestFinishedBlock)(id errorCode);

/// HTTP Request method.
typedef NS_ENUM(NSInteger, YFRequestMethod) {
    YFRequestMethodGET = 0,
    YFRequestMethodPOST
};

@interface YFRequestManager : AFHTTPSessionManager

/**
 * AFHTTPSessionManager
 */
+ (YFRequestManager *)sharedManager;

/**
 *  请求函数
 *
 *  @param method        请求方式
 *  @param params        请求参数
 *  @param key           请求key
 *  @param failedBlock   失败block
 *  @param finishedBlock 成功block
 */
+ (NSURLSessionDataTask *)startRequestWithMethod:(YFRequestMethod)method
                                          params:(NSDictionary *)params
                                             key:(NSString *)key
                                        finished:(YFRequestFailedBlock)finishedBlock
                                          failed:(YFRequestFinishedBlock)failedBlock;


+ (NSURLSessionDataTask *)postDataWithParams:(NSDictionary *)params
                                     andData:(NSArray *)dataArray
                                      toFile:(NSArray *)fileArray
                                         key:(NSString *)key
                                    finished:(YFRequestFailedBlock)finishedBlock
                                      failed:(YFRequestFinishedBlock)failedBlock;

+ (void)cancelRequest;

@end

NS_ASSUME_NONNULL_END
